package tree;

//二叉树的建立 与遍历
public class BainaryTree {

	private int data;
	private BainaryTree left;
	private BainaryTree right;
	
	public BainaryTree() {};
	public BainaryTree(int data) {
		this.data = data;
	}
	
	//前序遍历
	public static void preOrder(BainaryTree root) {
		System.out.println(root.data);
		if(root.left != null) {
			preOrder(root.left);
		}
		if(root.right != null) {
			preOrder(root.right);
		}
		
	}
	//中序遍历
	public static void midOrder(BainaryTree root) {
		if(root.left != null) {
			midOrder(root.left);
		}
		System.out.println(root.data);
		
		if(root.right != null) {
			midOrder(root.right);
		}
	}
	
	//后序遍历
	public static void sufOrder(BainaryTree root) {
		if(root.left != null) {
			sufOrder(root.left);
		}
		if(root.right != null) {
			sufOrder(root.right);
		}
		System.out.println(root.data);
	}
	
	public void insertLeft(BainaryTree left) {
		
	}
	
	public int getData() {
		return data;
	}



	public void setData(int data) {
		this.data = data;
	}



	public BainaryTree getLeft() {
		return left;
	}



	public void setLeft(BainaryTree left) {
		this.left = left;
	}



	public BainaryTree getRight() {
		return right;
	}



	public void setRight(BainaryTree right) {
		this.right = right;
	}

	


	@Override
	public String toString() {
		return "BainaryTree [data=" + data + "]";
	}



	public static void main(String[] args) {
		BainaryTree tree1 = new BainaryTree(1);
		BainaryTree tree2 = new BainaryTree(2);
		BainaryTree tree3 = new BainaryTree(3);
		BainaryTree tree4 = new BainaryTree(4);
		BainaryTree tree5 = new BainaryTree(5);
		BainaryTree tree6 = new BainaryTree(6);
		BainaryTree tree7 = new BainaryTree(7);
		tree1.left = tree2;
		tree1.right = tree3;
		tree2.right = tree4;
		tree3.right = tree5;
		tree4.left = tree6;
		tree4.right = tree7;
		
		preOrder(tree1);
		
	}
}
